package com.smart.wap.bodys;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.crypto.digest.DigestUtil;
import com.smart.common.entities.domain.SmartPattern;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * @author Administrator
 */
public class RegisterBody {

    @Data
    @ApiModel("RegisterBody1")
    public static class CaptchaBody implements Serializable {
        @ApiModelProperty(value = "手机号码", required = true)
        @NotBlank(message = "手机号码 不能为空")
        @Pattern(regexp = SmartPattern.PHONE, message = "手机号码 格式不正确")
        private String phoneNumber;


        @ApiModelProperty(value = "11位时间戳", required = true)
        @NotNull(message = "时间戳 不能为空")
        private Long timestamp;


        @ApiModelProperty(value = "签名字符串  算法:大写32位MD5(SMART-手机号码-时间戳) ,中间有短横线 ", required = true)
        @Length(min = 32, max = 32, message = "获取短信签名错误")
        private String sign;


//        public void checkSign() {
//            String sourceStr = String.format("SMART-%s-%s", this.phoneNumber, this.timestamp);
//            String sign2 = DigestUtil.md5Hex(sourceStr).toUpperCase();
//            Assert.equals(this.sign, sign2, "获取短信验证码签名错误");
//            long abs = Math.abs(DateUtil.currentSeconds() - this.timestamp);
//            Assert.isTrue(abs <= 300L, "设备时间异常:请校验当前设备的时间后再进行短信发送");
//        }
    }


    /**
     * 电话号码登录对象
     *
     * @author xiaxuqiu
     * @date 2023/09/10
     */

    @Data
    @ApiModel("RegisterBody2")
    public static class RegBody implements Serializable {

        @ApiModelProperty(value = "手机号码", required = true)
        @NotBlank(message = "手机号码 不能为空")
        @Pattern(regexp = SmartPattern.PHONE, message = "手机号码 格式不正确")
        private String phoneNumber;

        @ApiModelProperty(value = "手机验证码", notes = "测试验证码:6个0", required = true)
        @NotBlank(message = "手机验证码 不能为空")
        @Length(min = 4, max = 6, message = "手机验证码 字符长度错误")
        private String captcha;

        @ApiModelProperty("注册活动ID")
        private Long activityId;

        @ApiModelProperty("邀请人ID")
        private Long inviterId;

    }



    /**
     * 电话号码登录对象
     *
     * @author xiaxuqiu
     * @date 2023/09/10
     */

    @Data
    @ApiModel("RegisterBody2")
    public static class MerchantRegBody implements Serializable {

        @ApiModelProperty(value = "手机号码", required = true)
        @NotBlank(message = "手机号码 不能为空")
        @Pattern(regexp = SmartPattern.PHONE, message = "手机号码 格式不正确")
        private String phoneNumber;

        @ApiModelProperty(value = "手机验证码", notes = "测试验证码:6个0", required = true)
        @NotBlank(message = "手机验证码 不能为空")
        @Length(min = 4, max = 6, message = "手机验证码 字符长度错误")
        private String captcha;

        @ApiModelProperty("客户经理Id")
        @NotNull(  message = "客户经理Id 不能为空")
        private Long managerId;

        @ApiModelProperty("邀请人ID")
        private Long inviterId;


        @ApiModelProperty("微信公众号OpenId")
        @NotBlank(  message = "微信公众号OpenId 不能为空")
        private String  mpOpenId;

    }


}
